package cn.work.service;

import cn.work.bean.Doctor;
import cn.work.dao.DoctorDao;

import java.sql.SQLException;
import java.util.List;

public class DoctorService {
    private DoctorDao doctorDao;

    public DoctorService() {
        this.doctorDao = new DoctorDao();
    }

    public List<Doctor> getAllDoctors() {
        try {
            return doctorDao.getAllDoctors();
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public Doctor getDoctorById(int id) {
        try {
            return doctorDao.getDoctorById(id);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public boolean addDoctor(Doctor doctor) {
        try {
            return doctorDao.addDoctor(doctor);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean updateDoctor(Doctor doctor) {
        try {
            return doctorDao.updateDoctor(doctor);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean deleteDoctor(int id) {
        try {
            return doctorDao.deleteDoctor(id);
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public List<Doctor> searchDoctors(String keyword) {
        try {
            return doctorDao.searchDoctors(keyword);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
}